package com.ddch.testioc.test;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.HashMap;

/**
 * created by 韦敏敏
 * on 2019/12/17
 */
public class OnClickListenerHandler implements InvocationHandler {
    private Object targetObject;
    public OnClickListenerHandler(Object object){
        this.targetObject = object;
    }
    private java.util.Map<String, Method> methods = new HashMap<>();
    public void addMethod(String methodName, Method method){
        methods.put(methodName, method);
    }
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        String methodName = method.getName();
        Method realMethod = methods.get(methodName);
        return realMethod.invoke(targetObject, args);
    }
}
